# -*- coding: utf-8 -*-
import scrapy
from dangdang.items import DangdangItem
from scrapy.http import Request

class DdSpider(scrapy.Spider):
    name = 'dd'
    allowed_domains = ['dangdang.com']
    start_urls = ['http://dangdang.com/']

    def parse(self, response):
        item = DangdangItem()
        item['title'] = response.xpath('//ul[@class = "bigimg"]/li/a/@title').extract()
        item['link'] = response.xpath('//ul[@class = "bigimg"]/li/a/@href').extract()
        item['comment'] = response.xpath('//p[@class="search_star_line"]/a/text()').extract()
        item['press'] = response.xpath('//p[@class="search_book_author"]//a[@name = "P_cbs"]/text()').extract()
        yield item
        for i in range(1, 11):
            url = 'http://category.dangdang.com/pg%s-cp01.54.06.00.00.00.html' % str(i)
            yield Request(url, callback = self.parse)
            